package Day08_18;
import java.io.*;

public class HomeWork_CopyDirectory {
    public static void main(String[] args) {
        FileInputStream fis = null;
        FileOutputStream fos = null;

        try {
            fis = new FileInputStream("C:\\Temp");
            fos = new FileOutputStream("D:\\Temp");

            File f1 = new File("C:\\Temp");
            File[] files = f1.listFiles();

            for (File file:files){
                if(file.isDirectory()){
                    //一直找
                    Found(file);
                }
                if(file.isFile()){
                    //开始拷贝
                    byte[] bytes = new byte[1024*1024];
                    int readCount = 0;
                    while ((readCount = fis.read(bytes))!=-1){
                        fos.write(bytes,0,readCount);
                    }
                }


            }
            fos.flush();

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if(fis!=null){
                try {
                    fis.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
                if(fos!=null){
                    try {
                        fos.close();
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }

    }
    public static void Found(File f1){
        File[] files = f1.listFiles();
        for (File file:files){
            if(file.isDirectory()){
                Found(file);
            }
        }

    }
}
